<style type="text/css" media="all">@import url(master.css);</style>

<?php
	
	/**
	* Recentlyadded Product List Module
	*
	* @version $Id: mod_mallkit_recentlyadded.php 0001 2009-01-15 10:29:00 saurabh_atr $
	* @package Mallkit
	* @subpackage Modules
	*
	* @copyright Copyright (C) 2004-2009 saurabh - All rights reserved.
	* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
	* Mallkit eCommerce is free software. This version may have been modified pursuant
	* to the GNU General Public License, and as distributed it includes or
	* is derivative of works licensed under the GNU General Public License or
	* other free or open source software licenses.
	* See /administrator/components/com_mallkit/COPYRIGHT.php for copyright notices and details.
	*
	* http://www.mallkit.org
	*/
	
	// no direct access
	defined('_JEXEC') or die('Restricted access');
	jimport('phpxmlrpc.xmlrpc');
	
	// get joomla instance of client
	$host = JURI::getInstance();
	
	// get host of clients joomla instance and set it to the $host variable
	$host = $host->getHost();
	
	// get the clients true joomla instance root (path-only)
	$instance_path = JURI::root(true);
	// append the xmlrpc directory and set to the $path variable
	$xml_path = JURI::root(true)."/xmlrpc/";
		
	// create an instance of client implementation
	$client = new xmlrpc_client($xml_path, $host);
	
	// define global xmlrpc variable types
	global $xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble, $xmlrpcString, $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray, $xmlrpcStruct, $xmlrpcValue;

	$recentlyadded_product_category = $params->get('recentlyadded_product_category');  // Filter products from categories
	$recentlyadded_product_add_to_cart = $params->get('recentlyadded_product_add_to_cart'); // Display Cart Button
	$display_layout = $params->get( 'recentlyadded_product_layout', "vertical" ); // Display Layout
	$recentlyadded_product_show_price= $params->get('recentlyadded_product_show_price') == 1; // Display Price	

	// pass the value to xmlrpc
	$msg = new xmlrpcmsg("mallkit.getRecentlyaddedProductList", array(new xmlrpcval(0, $xmlrpcString), new xmlrpcval($params->get('recentlyadded_product_limit'), $xmlrpcInt), new xmlrpcval($recentlyadded_product_category, $xmlrpcString)));

	// fetching value back from xmlrpc
	$response = $client->send($msg);

	// BEGIN - RECENTLYADDED PRODUCT LIST
	if ((boolean)$response->value())
	{
		// decoding the xmlrpc response into array
		$products = php_xmlrpc_decode($response->value());

		// To avoid divide by zero error
		if(count($products))
		{
					
			// This will balance the display width per product if layout is horizontal
			$width = 100/count($products);
			
			// extracting the array returned from xmlrpc and display in module
			foreach($products as $product) 
			{
				if($display_layout == "horizontal") echo '<div align="center" style="float:left;width:' . $width . '%;">';
				else echo '<div align="center">';
	
				echo '<a href="#"><img width="100px" src="'.$instance_path.'/images/images/'.$product['image'].'" /></a>';
				echo '<div>';
				echo '<a title="'.$product['name'].'" href="#">'.$product['name'].'</a>';
				echo '</div>';
	
				// display price of the product
				if($recentlyadded_product_show_price)
				{
					echo '<div>Price: '.$product['price'].'</div>';
				}

				// display the add to cart button
				if($recentlyadded_product_add_to_cart)
				{
					echo '<div><input name="addtocart" class="button" type="button" value="Add to Cart" /></div>';
				}
				echo '</div>';
			}
		}	
		else
		{
			echo '-- No Product Available -- ';
		}	
		echo '<div style="clear:both;"></div>';
	}
	else
	{

		// error alert if xmlrpc call connection unsuccessfull
		echo "Error to procedure call.";
	}

	// END - RECENTLYADDED PRODUCT LIST
?>